package com.kai.awt.event;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
 * @Author Mr.Yan
 * @create 2022/3/20 15:22
 * @description:
 */
public class Demo1 {

    public static void main(String[] args) {

        Frame frame = new Frame("event");

        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        Button button = new Button("enter");
        TextField textField = new TextField(20);

        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                textField.setText("hello,world");
            }
        });

        textField.addTextListener(new TextListener() {
            @Override
            public void textValueChanged(TextEvent e) {
                System.out.println(textField.getText());
            }
        });


        frame.add(button,BorderLayout.SOUTH);
        Box horizontalBox = Box.createHorizontalBox();
        Choice choice = new Choice();
        choice.add("男");
        choice.add("女");
        choice.add("人妖");
        choice.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                System.out.println(choice.getSelectedItem());
            }
        });
        horizontalBox.add(choice);
        horizontalBox.add(textField);

        frame.add(horizontalBox);





        frame.pack();
        frame.setVisible(true);

    }
}
